package cn.rocky.prepare;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

public class checkDistances {

    public static boolean checkDistances(String s, int[] distance) {
        int number = s.length() >> 1;
        HashSet set = new HashSet();
        Map<Character,Integer> map = initMap(distance);
        for (int i = 0; i < s.length(); i++) {
            if (set.contains(s.charAt(i))) {
                continue;
            }
            Integer value = map.get(s.charAt(i));
            char c = s.charAt(i);
            int len = i + value + 1;
            if (len < s.length()) {
                char c1 = s.charAt(len);
                if (c != c1) {
                    return false;
                }
            } else {
                return false;
            }
            set.add(s.charAt(i));
        }
        return true;
    }

    public static Map initMap(int[] distance) {
        HashMap<Character, Integer> map = new HashMap<>();
        map.put('a',distance[0]);
        map.put('b',distance[1]);
        map.put('c',distance[2]);
        map.put('d',distance[3]);
        map.put('e',distance[4]);
        map.put('f',distance[5]);
        map.put('g',distance[6]);
        map.put('h',distance[7]);
        map.put('i',distance[8]);
        map.put('j',distance[9]);
        map.put('k',distance[10]);
        map.put('l',distance[11]);
        map.put('m',distance[12]);
        map.put('n',distance[13]);
        map.put('o',distance[14]);
        map.put('p',distance[15]);
        map.put('q',distance[16]);
        map.put('r',distance[17]);
        map.put('s',distance[18]);
        map.put('t',distance[19]);
        map.put('u',distance[20]);
        map.put('v',distance[21]);
        map.put('w',distance[22]);
        map.put('x',distance[23]);
        map.put('y',distance[24]);
        map.put('z',distance[25]);
        return map;
    }

    public static void main(String[] args) {
        String s = "abaccb";
        int[] dis = new int[]{1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
        String s1 = "aa";
        String s2 = "rryzglzgyl";
        int[] dis1 = new int[]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
        int[] dis2 = new int[]{1,9,22,36,3,20,2,42,47,5,35,3,11,37,14,37,44,0,15,9,19,44,16,32,5,2};
        //System.out.println(checkDistances(s, dis));
        //System.out.println(checkDistances(s1, dis1));
        System.out.println(checkDistances(s2, dis2));

    }
}
